Hiện thực trong Perl Bảng_điều_phối

Bên dưới là một cách hiện thực bảng điều phối trong Perl, sử dụng một hash để chứa tham chiếu tới mã (còn gọi là con trỏ hàm).

 # Define the table using one anonymous code-ref and one named code-ref my %dispatch = (   "-h" => sub {  return "hello\n"; },   "-g" => \&say_goodbye);  sub say_goodbye {   return "goodbye\n"; }  # Fetch the code ref from the table, and invoke it my $sub = $dispatch{$ARGV[0]}; print $sub ? $sub->(): "unknown argument\n";

Chạy chương trình Perl này bằng lệnh perl greet -h sẽ xuất ra "hello", và chạy bằng lệnh perl greet -g sẽ xuất ra "goodbye".